package cn.itcast.bos.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.bos.domain.base.Courier;
import cn.itcast.bos.repository.CourierRepository;
import cn.itcast.bos.service.CourierService;

@Service
@Transactional
public class CourierServiceImpl implements CourierService{
	@Autowired
	private CourierRepository courierRepository;

	/**
	 * 添加快递员
	 */
	public void addCourier(Courier courier) {
		courierRepository.save(courier);
	}
	
	/**
	 * 分页查询快递员
	 * @return 
	 */
	@Override
	public Page<Courier> findCourierByPage(Specification<Courier> spec,Pageable pageable) {
		Page<Courier> list = courierRepository.findAll(spec,pageable);
		return list;
	}

	/**
	 * 修改快递员
	 */
	@Override
	public void updateCourier(Courier courier) {
		courierRepository.save(courier);
		
	}

	/**
	 * 批量作废快递员
	 */
	@Override
	public void batchDeleteCourier(String[] idArr) {
		if (idArr != null && idArr.length > 0){
			for (String id : idArr) {
				// 1表示作废,
				courierRepository.updateDeltag(Integer.parseInt(id),'1');
			}
		}
		
	}

	/**
	 * 批量还原快递员
	 */
	@Override
	public void batchRestoreCourier(String[] idArr) {
		if (idArr != null && idArr.length > 0){
			for (String id : idArr) {
				// 1表示作废,
				courierRepository.updateDeltag(Integer.parseInt(id),null);
			}
		}
		
	}

}
